-
Notifications
You must be signed in to change notification settings - Fork 693
MSSQL: Support THROW statement
#2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
|
Hi @iffyio I would like modify the PR title to |
THROW statement
|
Done! |
|
Thanks! Please let me know if there is anything could be better in this pr, thanks! |
src/ast/mod.rs
Outdated
| Throw { | ||
| /// Error number expression. | ||
| error_number: Option<Box<Expr>>, | ||
| /// Error message expression. | ||
| message: Option<Box<Expr>>, | ||
| /// State expression. | ||
| state: Option<Box<Expr>>, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're slowly moving away from this representation over to having all statements wrapped in a named struct. As a result, can we do something like this instead?
struct Throw { ... }
Statement::Throw(Throw)See the RAISE statement for an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your information. I just update with wrapped named struct.
src/parser/mod.rs
Outdated
| Keyword::RELEASE => self.parse_release(), | ||
| Keyword::COMMIT => self.parse_commit(), | ||
| Keyword::RAISERROR => Ok(self.parse_raiserror()?), | ||
| Keyword::THROW => Ok(self.parse_throw()?), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Keyword::THROW => Ok(self.parse_throw()?), | |
| Keyword::THROW => { | |
| self.prev_token(); | |
| self.parse_throw().map(Into::into) | |
| }, |
see RAISE for an example. we're moving to have the statement parsing functions return the actual struct instead of a Statement enum variant. Also it would be ideal that the parse_throw is a standalone function (able to parse a THROW statement) so we rewind the token before invoking it
src/parser/mod.rs
Outdated
| if self.peek_token_ref().token == Token::SemiColon | ||
| || self.peek_token_ref().token == Token::EOF | ||
| { | ||
| return Ok(Statement::Throw { | ||
| error_number: None, | ||
| message: None, | ||
| state: None, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if self.peek_token_ref().token == Token::SemiColon | |
| || self.peek_token_ref().token == Token::EOF | |
| { | |
| return Ok(Statement::Throw { | |
| error_number: None, | |
| message: None, | |
| state: None, | |
| }); | |
| } |
I think we can skip this logic, it would be expected for the function to return an error if the input is empty (per the previous comment about making this function stand-alone)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that makes sense to me. Just moved~
Co-Authored-By: Ifeanyi Ubah <7816405+iffyio@users.noreply.github.com>
f184eff to
4c18f7a
Compare
Why
The MSSQL THROW statement was missing from the sqlparser, preventing parsing of T-SQL error handling code.
How